package com.bzframework.network.tcp;

import com.bzframework.network.DefaultNetworkType;
import com.bzframework.network.NetworkType;
import io.vertx.core.net.NetSocket;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * VertxTcpServer
 */
public class VertxTcpServer implements TcpServer {

    private final List<NetSocket> netSockets = new CopyOnWriteArrayList<>();

    @Override
    public String getId() {
        return DefaultNetworkType.TCP_SERVER.name();
    }

    @Override
    public NetworkType getType() {
        return DefaultNetworkType.TCP_SERVER;
    }

    @Override
    public void shutdown() {
        netSockets.forEach(NetSocket::close);
    }

    public void register(NetSocket netSocket) {
        netSockets.add(netSocket);
    }

    public void remove(NetSocket netSocket) {
        netSockets.remove(netSocket);
    }
    public List<NetSocket> getAll() {
        return netSockets;
    }
}
